Skip to content

Conversation

@NiveditJain
Copy link
Member

@nk-ag this will fix the issue you are facing (:

@NiveditJain NiveditJain requested a review from nk-ag August 19, 2025 07:56
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 19, 2025

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Corrected parent-child lineage handling in executed states to remove self-references.
    • Fixes confusing loops or redundant entries in execution history and dependency views.
    • Ensures consistent lineage across runs with no outputs and runs with multiple outputs.
    • Improves accuracy of downstream tracking without impacting background task behavior.

Walkthrough

Removed all augmentation of state.parents with the current state's own identifier across execution paths. New and existing states now retain the original parents mapping without adding a self-referential entry. Control flow, function signatures, background tasks, and error handling remain unchanged.

Changes

Cohort / File(s) Summary
Executed state parents mapping change
state-manager/app/controller/executed_state.py
Deleted additions of {state.identifier: state.id} to state.parents in both zero-output and multi-output paths; child states now receive parents=state.parents instead of a merged dict. No other logic altered.

Sequence Diagram(s)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

A whisker twitch, a parent’s map,
No self-loop now in our little app.
I hop through states, light on my feet,
Passing maps along, tidy and neat.
Carrot commit, with careful care—
Fewer crumbs, but all still there. 🥕✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @NiveditJain, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a bug where the parents field of a state object was being incorrectly updated to include the state's own ID, leading to self-referential parent relationships. The changes remove the erroneous logic that added the current state's ID to its parents dictionary during state execution and ensure that subsequent state creations correctly inherit the existing parent relationships without modification. This fix resolves an issue related to accurate parent ID handling within the state management system.

Highlights

  • Corrected Parent ID Assignment: The logic that incorrectly added the current state's ID to its own parents dictionary within the executed_state function has been removed. This was occurring both when body.outputs was empty and when it contained data.
  • Refined State Creation with Parent Inheritance: The create_next_state function now correctly passes the existing state.parents to new states, ensuring that parent relationships are maintained without self-referencing the current state as its own parent.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@codecov
Copy link

codecov bot commented Aug 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request aims to fix an issue with parent ID assignment for states. The changes correctly prevent a state from being assigned as its own parent and properly set the parentage for new states created from multiple outputs, treating them as siblings. While the logic of the fix seems correct, the corresponding unit tests have not been updated to include assertions for the parents field, which is a significant omission for a change of this nature. Additionally, I've identified some code duplication that could be refactored for better maintainability.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (5)
state-manager/app/controller/executed_state.py (5)

31-31: Pass identifiers to background tasks instead of full document instances

Handing a full State document to BackgroundTasks can introduce stale-data issues, heavier memory usage, and accidental coupling. Prefer passing state.id (and re-fetch inside the task), which also lets you drop the extra read after insert_many.

Apply this diff (if create_next_state supports fetching by id):

-            background_tasks.add_task(create_next_state, state)
+            background_tasks.add_task(create_next_state, state.id)
-            background_tasks.add_task(create_next_state, state)
+            background_tasks.add_task(create_next_state, state.id)
-                for inserted_state in inserted_states:
-                    background_tasks.add_task(create_next_state, inserted_state)
+                for inserted_state in inserted_states:
+                    background_tasks.add_task(create_next_state, inserted_state.id)

If create_next_state currently expects a State instance, I can provide a companion patch to refactor it to accept an id and perform a fresh lookup.

Also applies to: 38-38, 66-66


55-63: Skip re-query when scheduling background work (paired with id-passing)

If you switch to passing ids to the background task, you can avoid the extra find(In(State.id, inserted_ids)) round-trip altogether, scheduling tasks directly from inserted_ids.

Proposed adjustment:

-            if len(new_states) > 0:
-                inserted_ids = (await State.insert_many(new_states)).inserted_ids
-
-                inserted_states = await State.find(
-                    In(State.id, inserted_ids)
-                ).to_list()
-                
-                if len(inserted_states) != len(new_states):
-                    raise RuntimeError(f"Failed to insert all new states. Expected {len(new_states)} states, but only {len(inserted_states)} were inserted")
-
-                for inserted_state in inserted_states:
-                    background_tasks.add_task(create_next_state, inserted_state)
+            if new_states:
+                inserted_ids = (await State.insert_many(new_states)).inserted_ids
+                if len(inserted_ids or []) != len(new_states):
+                    raise RuntimeError(f"Failed to insert all new states. Expected {len(new_states)} states, but only {len(inserted_ids or [])} were inserted")
+                for inserted_id in inserted_ids:
+                    background_tasks.add_task(create_next_state, inserted_id)

26-39: Reduce duplication between empty/non-empty outputs branches

Both branches set status=EXECUTED, save, and enqueue create_next_state. Consider consolidating to reduce duplication and potential drift.

High-level idea:

  • Compute outputs = body.outputs[0] if body.outputs else {}
  • Set state.outputs = outputs, state.status = EXECUTED
  • Save once, add one background task
  • Then handle body.outputs[1:] for additional states

I can provide a concrete patch if you’d like.


70-72: Preserve traceback: use bare raise and log exception with stack

raise e can obscure the original traceback context. Prefer raise to rethrow the same exception and use an exception-aware logger to include the stack trace.

Apply this diff:

-    except Exception as e:
-        logger.error(f"Error executing state {state_id} for namespace {namespace_name}", x_exosphere_request_id=x_exosphere_request_id, error=e)
-        raise e
+    except Exception as e:
+        logger.exception(f"Error executing state {state_id} for namespace {namespace_name}", x_exosphere_request_id=x_exosphere_request_id, error=e)
+        raise

If LogsManager lacks exception, use logger.error(..., exc_info=True).


26-31: Add unit tests to guard the new parents semantics

We should assert that:

  • state.parents is not mutated in-place after execution.
  • New states created for outputs[1:] have parents equal to the original mapping, without any added self entry.

I can draft tests mirroring test_executed_state_empty_outputs to validate these invariants. Want me to open a testing PR or push commits to this one?

Also applies to: 34-39, 41-53

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 3804274 and 0f395fb.

📒 Files selected for processing (1)
  • state-manager/app/controller/executed_state.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
state-manager/app/controller/executed_state.py (1)
state-manager/tests/unit/controller/test_executed_state.py (1)
  • test_executed_state_empty_outputs (203-239)
🔇 Additional comments (2)
state-manager/app/controller/executed_state.py (2)

26-39: LGTM: self-parent augmentation removed on existing state paths

Confirmed we no longer augment state.parents in either path (empty outputs vs. first output). This aligns with the PR objective to stop self-referential parent entries.


41-53: Downstream parents logic verified safe
I confirmed in state-manager/app/tasks/create_next_state.py (around lines 62–68 and 109–115) that:

  • The code explicitly skips state.identifier when iterating dependencies.
  • All lookups against state.parents target only other node identifiers (dependencies/inputs).

No downstream logic expects the current state’s own ID in parents. This change is safe.

@NiveditJain NiveditJain merged commit 3b6c274 into exospherehost:main Aug 19, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant